home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / undo / undoFileAddSlotted.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  6.1 KB  |  240 lines

  1. /*
  2.  *   $RCSfile: undoFileAddSlotted.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:03 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "pool.h"
  46. #include "tid.h"
  47. #include "io.h"
  48. #include "lock.h"
  49. #include "object.h"
  50. #include "msgdefs.h"
  51. #include "thread.h"
  52. #include "latch.h"
  53. #include "semaphore.h"
  54. #include "link.h"
  55. #include "lsn.h"
  56. #include "bf.h"
  57. #include "log.h"
  58. #include "volume.h"
  59. #include "logrecs.h"
  60. #include "openlog.h"
  61. #include "trans.h"
  62. #include "bitmap.h"
  63. #include "file.h"
  64. #include "consist.h"
  65. #include "undo.h"
  66. #include "io_extfuncs.h"
  67. #include "bf_extfuncs.h"
  68. #include "bm_extfuncs.h"
  69. #include "fi_extfuncs.h"
  70. #include "fi_intfuncs.h"
  71. #include "log_extfuncs.h"
  72. #include "undo_extfuncs.h"
  73. #include "logaction.h"
  74. #include "util_funcs.h"
  75. #include "thread_globals.h"
  76. #include "bf_globals.h"
  77. #ifdef INIT_LRC_IS_LSN
  78. #   include "log_globals.h"
  79. #endif
  80.  
  81.  
  82.  void
  83. undoFileAddSlotted (
  84.  
  85.     LOGRECORDHDR        *recordHeader 
  86. )
  87. {
  88.  
  89.     VOLREC                *volRec;
  90.     PID                    *rootPID;
  91.     PID                    lastPID;
  92.     NODEPAGE            *nodePage;
  93.     SLOTTEDPAGE            *slottedPage;
  94.     GROUPLINK            *nodeLink = NULL;
  95.     GROUPLINK            *groupLink = NULL;
  96.     LOGRECORDINFO        recordInfo;
  97.     BOOL                firstPage;
  98.     FORCEMARK            forceMark;
  99.     LSN                    lsn;
  100.     LRC                    *rootLRC;
  101.     LRC                    tempLRC;    
  102.  
  103.  
  104.     TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN.offset));
  105.  
  106.     /*
  107.      *  get a pointer to the file root page id
  108.      *  get flag for whether this is the first page in the file
  109.      */
  110.     rootPID = &(recordHeader->actionPid);
  111.     firstPage = *(BOOL*) GET_LOG_IMAGE(recordHeader, 0);
  112.     TRPRINT(TR_IO, TR_LEVEL_2, ("file root pid:%d", rootPID->page));
  113.  
  114.     if ((volRec = io_FindVolRec(rootPID->volid)) == NULL)    {
  115.         SM_ERROR(TYPE_FATAL, Active->errno);
  116.     }
  117.  
  118.     /*
  119.      * Read in first page of file and grab node type
  120.      */
  121.     if ((nodeLink = bf_ReadPage(UserBufGroup, rootPID, FILE_PAGE2SIZE, BF_SEM)) == NULL) {
  122.  
  123.         SM_ERROR(TYPE_FATAL, Active->errno);
  124.     }
  125.  
  126.     /*
  127.      *    get a pointer to the node page
  128.      */
  129.     nodePage = (NODEPAGE *) nodeLink->bufFrame;
  130.  
  131.     /*
  132.      *    undo the update to the root page
  133.      */
  134.     if (firstPage) {
  135.  
  136.         /*
  137.          *    record that the file contains no pages
  138.          */
  139.         nodePage->header.firstLogicalNode = NULLPID;
  140.         nodePage->header.lastLogicalNode = NULLPID;
  141.  
  142.     } else {
  143.  
  144.         /*
  145.          *    Get a pointer to the last slotted page in the file
  146.          */
  147.         SM_ASSERT(LEVEL_3, 2*sizeof(SHORTPID) == GET_LOG_IMAGE_SIZE(recordHeader, 1));
  148.         /* get second pid in image 1 */
  149.         lastPID.page = *(((SHORTPID*) GET_LOG_IMAGE(recordHeader, 1))+1);
  150.         lastPID.volid = rootPID->volid;
  151.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("last slotted page:%d", lastPID.page));
  152.  
  153.         /*
  154.          *    restore the old lastLogicalNode
  155.          */
  156.         nodePage->header.lastLogicalNode = lastPID.page;
  157.  
  158.         /*
  159.          *    read in last page of the file and 
  160.          *     undo the link update
  161.          */
  162.         if ((groupLink = bf_ReadPage(UserBufGroup, &lastPID, SLOTTED_PAGE2SIZE, BF_SEM)) == NULL) {
  163.  
  164.             SM_ERROR(TYPE_FATAL, Active->errno);
  165.         }
  166.         groupLink->pageHash->pageType = PAGE_SLOTTED;
  167.     
  168.         /*
  169.          *    get a pointer to the node page
  170.          */
  171.         slottedPage = (SLOTTEDPAGE *) groupLink->bufFrame;
  172.  
  173.         /*
  174.          *    Restore the old value of the link 
  175.          */
  176.         slottedPage->header.nextLogicalPid = NULLPID;
  177.     }
  178.  
  179.     /*
  180.      *  increment the lrc on the page
  181.      */
  182.     rootLRC = &(((NODEHEADER *) nodeLink->bufFrame)->lrc);
  183.     INCREMENT_LRC(rootLRC);
  184.  
  185.     /*
  186.      *    initialize the log information
  187.      */
  188.     recordInfo.type            = LOG_REC_TYPE_COMPENSATION;
  189.     recordInfo.action        = LOG_ACTION_FILE_REMOVE_SLOTTED;
  190.     recordInfo.actionPid    = rootPID;
  191.     recordInfo.actionLRC    = rootLRC;
  192.     recordInfo.imageSize[0] = sizeof(BOOL);
  193.     recordInfo.imageData[0] = (VOID *) &firstPage;
  194.     recordInfo.flags        = NOFLAGS;
  195.     recordInfo.nextUndoLSN    = recordHeader->previousLSN;
  196.     if (firstPage) {
  197.         recordInfo.imageCount   = 1;
  198.     } else {
  199.         tempLRC = slottedPage->header.lrc;
  200.         (void) GENERATE_LRC(&tempLRC);
  201.         recordInfo.imageCount   = 3;
  202.         recordInfo.imageSize[1] = sizeof(SHORTPID);
  203.         recordInfo.imageData[1] = (VOID *) &(lastPID.page);
  204.         recordInfo.imageSize[2] = sizeof(LRC);
  205.         recordInfo.imageData[2] = (VOID *) &tempLRC;
  206.     }
  207.  
  208.     /*
  209.      *    write the record to the log
  210.      */
  211.     if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec, &recordInfo,
  212.                               &lsn, NOFLAGS)) < 0)    {
  213.         
  214.         SM_ERROR(TYPE_FATAL, Active->errno);
  215.     }
  216.  
  217.     /*
  218.      *    For the file root page
  219.      *    mark the page dependency
  220.      *    release  the page semaphore
  221.      *    release and dirty the page
  222.      */
  223.     DEPEND_LOG(nodeLink->pageHash, forceMark, &lsn, rootLRC);
  224.     signalSemaphore( &(nodeLink->pageHash->semaphore) );
  225.     bf_UnfixPage(nodeLink, BF_DEFAULT, TRUE);
  226.  
  227.  
  228.     /*
  229.      *    For the last slotted page
  230.      *    mark the page dependency
  231.      *    release  the page semaphore
  232.      *    release and dirty the page
  233.      */
  234.     if (!firstPage)  {
  235.         DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, &tempLRC);
  236.         signalSemaphore( &(groupLink->pageHash->semaphore) );
  237.         bf_UnfixPage(groupLink, BF_DEFAULT, TRUE);
  238.     }
  239. }
  240.